﻿#include "tcts.h"
#include "ui_tcts.h"

tcts::tcts(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::tcts)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::WindowStaysOnTopHint);
    this->setAttribute(Qt::WA_QuitOnClose, false);
    this->setWindowModality(Qt::ApplicationModal);
}

tcts::~tcts()
{
    delete ui;
}

void tcts::infochange(QString name,QString path,QString info,bool bt1,bool bt2){
    this->setWindowTitle(name);
    ui->label->setStyleSheet("border-image: url(:/pic/picture/"+path+".png);");
    ui->label_2->setText(info);
    ui->label_2->setText(info);
    QFontMetrics fm(ui->label_2->font());
    QSize textSize = fm.size(Qt::TextSingleLine, info); // 假设我们不想要换行，只测量单行文本

    // 如果需要处理多行文本，你可能需要使用boundingRect而不是size
    // QRect textRect = fm.boundingRect(label->rect(), Qt::AlignLeft, text);
    // QSize textSize = textRect.size();

    // 设置QLabel的大小以匹配文本大小，并考虑一些额外的间距（如果需要）
    ui->label_2->setFixedSize(textSize + QSize(120, 40)); // 额外的宽度和高度
    this->setFixedSize(textSize + QSize(200, 140));
    ui->pushButton->setVisible(bt1);
    ui->pushButton_2->setVisible(bt2);
}

void tcts::on_pushButton_clicked()
{
    this->close();
}

void tcts::on_pushButton_2_clicked()
{
    this->close();
}
